using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using TPDSConfig;

namespace ImageReview
{
    public class TPDSWEBConfig
    {
        /// <summary>
        /// Retrieves configuration xml file. Will also cache file for later retrieval.
        /// </summary>
        public static TPDSConfig.TPDSConfig Load( string path )
        {
            // First check in data cache...
            if( HttpContext.Current.Cache[ "ConfigData" ] != null )
                return (TPDSConfig.TPDSConfig)HttpContext.Current.Cache[ "ConfigData" ];

            // Load file
            TPDSConfig.TPDSConfig ConfigFile = TPDSConfig.TPDSConfig.Load( path );
            if( ConfigFile == null )
                return null;

            // Cache the data
            HttpContext.Current.Cache.Insert(
                    "ConfigData", ConfigFile,
                    new System.Web.Caching.CacheDependency( TPDSConfig.TPDSConfig.ConfigFilePath( path ) ),
                    DateTime.MaxValue, TimeSpan.FromDays( 7 ) );

            return ConfigFile;
        }

    }
}
